//倒计时
!function ($) {

    var countDownFn = {

        init: function () {

            var $loseTime = $('#J-lose-time').val();
            countDownFn.countDown($('#J_count-down'), $loseTime);

        },
        /**
         * 倒计时钟
         * @param innoclockDc 引用的id
         * @param time (秒)  时间差
         */
        countDown: function (innoclockDc, time) {
            var timer = null;
            timer = setInterval(function () {
                var clockH = innoclockDc.find('.clock-h'),
                    clockM = innoclockDc.find('.clock-m'),
                    clockS = innoclockDc.find('.clock-s');

                //计数减一
                time -= 1;
                //计算时分秒
                var hours = Math.floor(time / (  60 * 60 )) % 24;
                var minutes = Math.floor(time / 60) % 60;
                var seconds = Math.floor(time % 60);

                var hoursT = hours < 10 ? '0' + hours : hours;
                var minutesT = minutes < 10 ? '0' + minutes : minutes;
                var secondsT = seconds < 10 ? '0' + seconds : seconds;
                if (hours < 0 || minutes < 0 || seconds < 0) {
                    clearInterval(timer);
                    //var $userOpBtn=$('#J_user-op-btn'),
                    //    url =$('#J-url').val();
                    //$userOpBtn.attr('href',url).removeClass('no-use').addClass('use').text('马上去抢');
                    hoursT = '00';
                    minutesT = '00';
                    secondsT = '00';

                }

                //将时分秒插入到html中
                clockH.text(hoursT);
                clockM.text(minutesT);
                clockS.text(secondsT);
            }, 1000);

        }
    };
    //初始化
    countDownFn.init();

}(jQuery);

//倒计时选项卡
!function ($) {
    var $courseSwitchA = $('.seckill-time-quantum').find('a');
    $courseSwitchA.on('click', function () {

        var self = $(this),
            selfIndex = self.index(),
            $courseCateList=self.parents('.seckill-hd').siblings('.seckill-bd').find('.goods-list-wrap');

        self.siblings().removeClass('time-quantum-cur');
        self.addClass('time-quantum-cur');

        $courseCateList.stop(true, true).animate({
            opacity: 'hide'
        }, 1000);
        $courseCateList.eq(selfIndex).stop(true, true).animate({
            opacity: 'show'
        }, 1000).siblings().stop(true, true).animate({
            opacity: 'hide'
        }, 1000);

    });
}(jQuery);